package com.ruoyi.program.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.program.domain.WxLearningMaterial;
import com.ruoyi.program.service.IWxLearningMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资料上传Controller
 * 
 * @author ruoyi
 * @date 2025-10-04
 */
@RestController
@RequestMapping("/learning/material")
public class WxLearningMaterialController extends BaseController
{
    @Autowired
    private IWxLearningMaterialService wxLearningMaterialService;

    /**
     * 查询资料上传列表
     */
    @PreAuthorize("@ss.hasPermi('learning:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxLearningMaterial wxLearningMaterial)
    {
        startPage();
        List<WxLearningMaterial> list = wxLearningMaterialService.selectWxLearningMaterialList(wxLearningMaterial);
        return getDataTable(list);
    }

    /**
     * 导出资料上传列表
     */
    @PreAuthorize("@ss.hasPermi('learning:material:export')")
    @Log(title = "资料上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxLearningMaterial wxLearningMaterial)
    {
        List<WxLearningMaterial> list = wxLearningMaterialService.selectWxLearningMaterialList(wxLearningMaterial);
        ExcelUtil<WxLearningMaterial> util = new ExcelUtil<WxLearningMaterial>(WxLearningMaterial.class);
        util.exportExcel(response, list, "资料上传数据");
    }

    /**
     * 获取资料上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('learning:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(wxLearningMaterialService.selectWxLearningMaterialByMaterialId(materialId));
    }

    /**
     * 新增资料上传
     */
    @PreAuthorize("@ss.hasPermi('learning:material:add')")
    @Log(title = "资料上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxLearningMaterial wxLearningMaterial)
    {
        return toAjax(wxLearningMaterialService.insertWxLearningMaterial(wxLearningMaterial));
    }

    /**
     * 修改资料上传
     */
    @PreAuthorize("@ss.hasPermi('learning:material:edit')")
    @Log(title = "资料上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxLearningMaterial wxLearningMaterial)
    {
        return toAjax(wxLearningMaterialService.updateWxLearningMaterial(wxLearningMaterial));
    }

    /**
     * 删除资料上传
     */
    @PreAuthorize("@ss.hasPermi('learning:material:remove')")
    @Log(title = "资料上传", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(wxLearningMaterialService.deleteWxLearningMaterialByMaterialIds(materialIds));
    }
}
